import javafx.util.Pair;

import java.util.PriorityQueue;

/**
* @description: 853. 车队
* @author hewei
* @date 2022/9/7 16:51
* @version 1.0
*/

public class CarFleet {

    public int carFleet(int target, int[] position, int[] speed) {
        PriorityQueue<Pair<Integer, Integer>> heap = new PriorityQueue<>((a ,b) -> b.getKey() - a.getKey());
        for (int i = 0; i < position.length; i++) {
            heap.add(new Pair<>(position[i], speed[i]));
        }
        int ans = 0;
        double lastTime = 0;
        while (!heap.isEmpty()) {
            Pair<Integer, Integer> pair = heap.poll();
            double temp = (target - pair.getKey()) / (double) pair.getValue();
            if (temp > lastTime) {
                lastTime = temp;
                ++ans;
            }
        }
        return ans;
    }
}
